define(function (require,exports,module) {
    var sTpl = require("./inventoryBasic.html");
    var VueComponent = Vue.extend({
        template: sTpl,
        data:function () {
            return {
                dialogAddSupplierFormVisible:false,
                dialogFormVisible:false,
                tableData: {},
                stockInFormInline:{
                    goodsInventoryPo:{},
                    supplier:'',
                    stockDate:'',
                    stockNum:'',
                    stockPrice:'',
                    total:'',
                    paidMoney:'',
                    debtMoney:'',
                    stockPeople:'',
                    invoiceNum:'',
                    remarks:''
                },
                goodsFormInline:{
                    goodsName:'',
                    goodsCategory:'',
                    goodsSpec:'',
                    goodsCode:'',
                    inventoryNum:0
                },
                suppliers:[],
                pickerOptions1: {
                shortcuts: [{
                    text: '今天',
                    onClick:function(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick:function(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick:function (picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            }
            }
        },
        methods:{
            pickTime1:function (val) {
                this.stockInFormInline.stockDate = val;
            },
            findAllSupplierMgrPo:function() {
                var $this = this;
                axios.get(basepath+"/api/inventoryManagement/findAllSupplierMgrPo"
                ).then(function (response) {
                    $this.suppliers=response.data;
                });
            },
            findGoodsBasic:function () {
                var $this = this;
                axios.get(basepath+"/api/inventoryManagement/findGoods"
                ).then(function (response) {
                    $this.tableData=response.data;
                });
            },
            addGoods:function () {
                this.$refs.baseTable.dialogFormVisible = true;


            },
            saveGoods:function () {
                this.stockInFormInline.total=this.computedTotal
                var $this = this;
                this.$refs.goodsFormInline.validate(function(validate){
                    if(validate){
                        axios.post(basepath+'/api/inventoryManagement/saveGoods',$this.goodsFormInline)
                            .then(function (response) {
                                $this.$refs["goodsFormInline"].resetFields();
                                $this.$notify({
                                    title: '保存成功',
                                    message: '保存成功'
                                });

                            });
                        $this.findGoodsBasic();
                        $this.$refs.baseTable.dialogFormVisible = false;

                    }else{
                        $this.$notify({
                            title: '保存失败',
                            message: '保存失败'
                        });
                        return  false;
                    }
                });

            },
            clearGoods:function () {
                this.$refs["goodsFormInline"].resetFields();
                this.$refs.baseTable.dialogFormVisible = false;
            },
            stockIn:function (scope) {
                this.dialogFormVisible=true;
                this.stockInFormInline.goodsInventoryPo=scope.row;
                var $this = this;
                axios.get(basepath+"/api/inventoryManagement/findAllSupplierMgrPo"
                ).then(function (response) {
                    $this.suppliers=response.data;
                });

            },
            stockOut:function (scope) {

            },
            saveStockIn:function () {
                var $this = this;
                this.$refs.stockInFormInline.validate(function(validate){
                    if(validate){
                        axios.post(basepath+'/api/inventoryManagement/saveStockIn',$this.stockInFormInline)
                            .then(function (response) {
                                $this.$refs["stockInFormInline"].resetFields();
                                $this.$notify({
                                    title: '保存成功',
                                    message: '保存成功'
                                });

                            });
                        $this.dialogFormVisible = false;
                        $this.findGoodsBasic();
                    }else{
                        $this.$notify({
                            title: '保存失败',
                            message: '保存失败'
                        });
                        return  false;
                    }
                });


            },
            clearStockIn:function () {
                this.$refs["stockInFormInline"].resetFields();
                this.dialogFormVisible=false;
            }
        },
        watch:{
        },
        created:function () {
            this.findGoodsBasic();

        },
        activated:function () {
            messages.$emit('change','商品库存');
        }
    })
    module.exports=VueComponent;
    module.exports.reDefine=function (val) {
        module.exports.type=val;
        return module.exports;
    }

})
